package com.ciwong.epaper.modules.bookstore.dao;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.ciwong.epaper.modules.bookstore.bean.BookstoreDataBean;
import com.ciwong.libs.utils.volley.BaseRequest;
import com.ciwong.libs.utils.volley.HttpRequest;
import com.ciwong.mobilelib.i.BaseCallBack;
import com.ciwong.mobilelib.utils.BaseRequestUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 教辅书城 相关网络请求
 * Created by luojinlei on 2017/12/26.
 */

public class BookstoreRequest {
	private static final String TAG = "BookstoreRequest";

	public static void getFirstPage(int brandId, String area, int gradeId, int schoolId, final BaseCallBack baseCallBack) {
		Map<String, String> params = new HashMap<>();
		params.put(BaseRequest.REQUEST_ACTION, BookstoreAction.ACTION_GET_BOOKSTORE_FIRST_TOKEN);
		params.put(BaseRequest.REQUEST_MODULES, BookstoreAction.class.getName());

		params.put("brandId", brandId + "");
		params.put("area", area);
		params.put("gradeId", gradeId + "");
		params.put("schoolId", schoolId + "");

		HttpRequest httpRequest = new HttpRequest(
				params,
				new Response.ErrorListener() {
			@Override
			public void onErrorResponse(VolleyError volleyError) {
				baseCallBack.failed(volleyError);
			}
		}, new BaseRequest.ResponseCallback() {

			@Override
			public void success(Object obj, int resultCode, int errorCode, String msg) {
				if (resultCode == 0 && errorCode == 0) {
					baseCallBack.success(obj);
				} else {
					baseCallBack.failed(errorCode, msg);
				}
			}

			@Override
			public void error(int errorCode, String msg) {
				baseCallBack.failed(errorCode, msg);
				super.error(errorCode, msg);
			}
		});
		httpRequest.setResponseDataType(HttpRequest.RESPONSE_DATA_TYPE_OBJECT);
		httpRequest.setResponseClazz(BookstoreDataBean.class);
		/*Type responseType = new TypeToken<List<SchoolDetail>>(){}.getType();
		request.setResponseType(responseType);*/
		BaseRequestUtil.getInstance().add(httpRequest);
		baseCallBack.setUrl(httpRequest.getUrl());
	}
}
